import os
from pyrd import SpoofingDetector
replay_model = SpoofingDetector('210401-rd')
# synthesis_model = SpoofingDetector('210420-ss-ivector-c-svc')
# synthesis_model = SpoofingDetector('210423-ss-ivector-c-svc-mix-data')

from ss_detector import SynthesisResNetDetector
synthesis_model = SynthesisResNetDetector('220412-lfcc-resnet-ocsoftmax')

# except ImportError:
#     print("Using fake model")   
#     class _M:
#         def score(self, x):
#             return [0 for _ in range(len(x))]
#     replay_model = _M()
#     synthesis_model = _M()

def replay_spoofing_detection(wav_path):
    score_list = replay_model.score([wav_path])
    s = score_list[0]
    if s > 0.5:
        result = '<span style="color: red">重放</span>'
    else:
        result = '<span style="color: green">原声</span>'
    return int(s*100), result


def synthesis_spoofing_detection(wav_path):
    score_list = synthesis_model.score([wav_path])
    s = score_list[0]
    if s > 0.5:
        result = '<span style="color: red">伪造</span>'
    else:
        result = '<span style="color: green">真实</span>'
    return int(s*100), result
